* Estimate Spatial Mismatch models for main results

* mean dependent variable
sum qtr_hire_`dep'_`suf' if qtr==8
local meandep=r(mean)

gen qtr2_hire_`dep'_`suf'=qtr_hire_`dep'_`suf'+0.5
gen qtrL_hire_`dep'_`suf'=log(qtr2_hire_`dep'_`suf')
replace qtrL_hire_`dep'_`suf'=-0.693 if qtr2_hire_`dep'_`suf'==0.5
replace qtrL_hire_`dep'_`suf'=2.2513 if qtr2_hire_`dep'_`suf'==9.5

* Alternative to main estimates, minimal controls
* ratio, access only
local depvar="qtrL_hire_`dep'_`suf'"
local smvar="ratio_predfeas_all_`lim'"
local control_output=""
local control_absorb=""
tobit `depvar' `smvar' `control_output' `control_absorb' ///
  if qtr==8, vce(cluster puma5) ll(-0.693) ul(2.251)
outreg2 `depvar' `smvar' `control_output' ///
  using `vnum'_`vers'_`dep'_`suf'_`prox'_`lim'.xls, ///
  excel title("tobit dependent:`dep' sufficient:`suf' proximity:`prox' limit:`lim'") ///
  ctitle("tob_acconly") addstat("Mean Dep Var",`meandep') onecol dec(3) replace

* Alternative to main estimates, worker controls (no neighborhood controls)
* ratio, access, worker
local depvar="qtrL_hire_`dep'_`suf'"
local smvar="ratio_predfeas_all_`lim'"
local control_output="`control_sex' `control_grp' `control_age' `control_earn' `control_job'"
local control_absorb="femy_fe*"
tobit `depvar' `smvar' `control_output' `control_sec' `control_seas' `control_absorb' ///
  if qtr==8, vce(cluster puma5) ll(-0.693) ul(2.251)
outreg2 `depvar' `smvar' `control_output' `control_sec' `control_seas' ///
  using `vnum'_`vers'_`dep'_`suf'_`prox'_`lim'.xls, ///
  excel title("tobit dependent:`dep' sufficient:`suf' proximity:`prox' limit:`lim'") ///
  ctitle("tob_accwrk") addstat("Mean Dep Var",`meandep') onecol dec(3) append

* Table 3, Colomn 1: Tobit
* ratio, MAIN, access, worker, neighborhood
local depvar="qtrL_hire_`dep'_`suf'"
local smvar="ratio_predfeas_all_`lim'"
local control_output="`contstand'"
local control_absorb="femy_fe*"
tobit `depvar' `smvar' `control_output' `control_sec' `control_seas' `control_absorb' ///
  if qtr==8, vce(cluster puma5) ll(-0.693) ul(2.251)
outreg2 `depvar' `smvar' `control_output' `control_sec' `control_seas' ///
  using `vnum'_`vers'_`dep'_`suf'_`prox'_`lim'.xls, ///
  excel title("tobit dependent:`dep' sufficient:`suf' proximity:`prox' limit:`lim'") ///
  ctitle("tob_awngh_T3_1") addstat("Mean Dep Var",`meandep') onecol dec(4) append

* Table E1: Estimates of all variables
* ratio, MAIN, access, worker, neighborhood
local depvar="qtrL_hire_`dep'_`suf'"
local smvar="ratio_predfeas_all_`lim'"
local control_output="`contstand'"
local control_absorb="femy_fe*"
tobit `depvar' `smvar' `control_output' `control_sec' `control_seas' `control_absorb' ///
  if qtr==8, vce(cluster puma5) ll(-0.693) ul(2.251)
outreg2 `depvar' `smvar' `control_output' `control_sec' `control_seas' ///
  using `vnum'_`vers'_`dep'_`suf'_`prox'_`lim'.xls, ///
  excel title("tobit dependent:`dep' sufficient:`suf' proximity:`prox' limit:`lim'") ///
  ctitle("tob_awngh_E1") addstat("Mean Dep Var",`meandep') onecol dec(3) append

* Table E2: Magnitude of Accessibility Effects
* At Median: see Predictive margins, _at=4, Margin
* 25pct: see Predictive margins, _at=3, Margin
* 75pct: see Predictive margins, _at=5, Margin
* Interquartile Diff.: 75pct-25pct
estimates store jobsearch
marginal_effect_predval val_`dep'`suf'_feas`lim' ratio_predfeas_all_`lim'

* Alternative to Table 3, Column 1: Cluster by tract
* ratio, MAIN, access, worker, neighborhood, cluster tract
local depvar="qtrL_hire_`dep'_`suf'"
local smvar="ratio_predfeas_all_`lim'"
local control_output="`contstand'"
local control_absorb="femy_fe*"
tobit `depvar' `smvar' `control_output' `control_sec' `control_seas' `control_absorb' ///
  if qtr==8, vce(cluster h_stfid) ll(-0.693) ul(2.251)
outreg2 `depvar' `smvar' `control_output' `control_sec' `control_seas' ///
  using `vnum'_`vers'_`dep'_`suf'_`prox'_`lim'.xls, ///
  excel title("tobit dependent:`dep' sufficient:`suf' proximity:`prox' limit:`lim'") ///
  ctitle("tob_awngh_clustrt") addstat("Mean Dep Var",`meandep') onecol dec(3) append

* two-way clustering
* fixed effects employer/year and geo
* two way se is sqrt(empyr+geo-empyr_geo)

* fe employer
encode seindom, gen(seindom_n)
egen seindom_u=group(seindom)
gen str7 seindom_s=string(seindom_u,"%07.0f")

tostring sep_year, gen(sep_year_s)
describe seindom seindom_u seindom_s sep_year_s h_stfidstring
list seindom seindom_u seindom_s in 1/10

* fe employer/year
gen seindom_sep_year_s=seindom_s+sep_year_s
destring seindom_sep_year_s, gen(seindom_sep_year_n)

* fe employer/year/puma
gen seindom_sep_year_puma5_s=seindom_s+sep_year_s+puma5_s
destring seindom_sep_year_puma5_s, gen(seindom_sep_year_puma5_n)

* fe employer/year/tract
gen seindom_sep_year_stfid_s=seindom_s+sep_year_s+h_stfidstring
destring seindom_sep_year_stfid_s, gen(seindom_sep_year_stfid_n)

describe seindom_sep_year_s seindom_sep_year_n seindom_sep_year_puma5_s seindom_sep_year_puma5_n seindom_sep_year_stfid_s seindom_sep_year_stfid_n

* Table 3, Column 2: OLS
* ratio - OLS to test importance of tobit, cluster puma
local depvar="qtrL_hire_`dep'_`suf'"
local smvar="ratio_predfeas_all_`lim'"
local control_output="`contstand'"
local control_absorb="femy_fe*"
reg `depvar' `smvar' `control_output' `control_sec' `control_seas' `control_absorb' ///
  if qtr==8, vce(cluster puma5)
outreg2 `depvar' `smvar' `control_output' `control_sec' `control_seas' ///
  using `vnum'_`vers'_`dep'_`suf'_`prox'_`lim'.xls, ///
  excel title("OLS dependent:`dep' sufficient:`suf' proximity:`prox' limit:`lim'") ///
  ctitle("ols_cluspuma_T3_2") addstat("Mean Dep Var",`meandep') onecol dec(4) append

* Alternative to Table 3, Column 2: Cluster by tract
* ratio - OLS to test importance of tobit, cluster tract
local depvar="qtrL_hire_`dep'_`suf'"
local smvar="ratio_predfeas_all_`lim'"
local control_output="`contstand'"
local control_absorb="femy_fe*"
reg `depvar' `smvar' `control_output' `control_sec' `control_seas' `control_absorb' ///
  if qtr==8, vce(cluster h_stfid)
outreg2 `depvar' `smvar' `control_output' `control_sec' `control_seas' ///
  using `vnum'_`vers'_`dep'_`suf'_`prox'_`lim'.xls, ///
  excel title("OLS dependent:`dep' sufficient:`suf' proximity:`prox' limit:`lim'") ///
  ctitle("ols_clustrt") addstat("Mean Dep Var",`meandep') onecol dec(4) append

* Alternative to Table 3, Column 3: FE within-differences
* ratio - employer/year FE, cluster employer/year (uses within differences)
local depvar="qtrL_hire_`dep'_`suf'"
local smvar="ratio_predfeas_all_`lim'"
local control_output="`contstand'"
local control_absorb=""
xtreg `depvar' `smvar' `control_output' `control_sec' `control_seas' `control_absorb' ///
  if qtr==8, i(seindom_sep_year_n) fe vce(cluster seindom_sep_year_n)
outreg2 `depvar' `smvar' `control_output' ///
  using `vnum'_`vers'_`dep'_`suf'_`prox'_`lim'.xls, ///
  excel title("xtreg dependent:`dep' sufficient:`suf' proximity:`prox' limit:`lim'") ///
  ctitle("fe_empwi_clusemp") addstat("Mean Dep Var",`meandep') onecol dec(4) append

* Alternative to Table 3, Column 3: FE absorb
* ratio - employer/year FE, cluster employer/year (same as absorb version below)
local depvar="qtrL_hire_`dep'_`suf'"
local smvar="ratio_predfeas_all_`lim'"
local control_output="`contstand'"
local control_absorb=""
xtreg `depvar' `smvar' `control_output' `control_sec' `control_seas' `control_absorb' ///
  if qtr==8, i(seindom_sep_year_n) fe vce(cluster seindom_sep_year_n) dfadj
outreg2 `depvar' `smvar' `control_output' ///
  using `vnum'_`vers'_`dep'_`suf'_`prox'_`lim'.xls, ///
  excel title("xtreg dependent:`dep' sufficient:`suf' proximity:`prox' limit:`lim'") ///
  ctitle("fe_empab_clusemp") addstat("Mean Dep Var",`meandep') onecol dec(4) append

* Table 3, Column 3: FE, Cluster by employer/year
* ratio - employer/year FE, cluster employer/year (absorb version)
local depvar="qtrL_hire_`dep'_`suf'"
local smvar="ratio_predfeas_all_`lim'"
local control_output="`contstand'"
local control_absorb=""
areg `depvar' `smvar' `control_output' `control_sec' `control_seas' `control_absorb' ///
  if qtr==8, absorb(seindom_sep_year_n) vce(cluster seindom_sep_year_n)
outreg2 `depvar' `smvar' `control_output' ///
  using `vnum'_`vers'_`dep'_`suf'_`prox'_`lim'.xls, ///
  excel title("areg dependent:`dep' sufficient:`suf' proximity:`prox' limit:`lim'") ///
  ctitle("fe_empab_clusemp_T3_3") addstat("Mean Dep Var",`meandep') onecol dec(4) append

* Table 3, Column 3: FE, Cluster by PUMA
* absorb needed for two-way clustering bc panels are not nested within clusters
* ratio - employer/year FE, cluster puma
local depvar="qtrL_hire_`dep'_`suf'"
local smvar="ratio_predfeas_all_`lim'"
local control_output="`contstand'"
local control_absorb=""
areg `depvar' `smvar' `control_output' `control_sec' `control_seas' `control_absorb' ///
  if qtr==8, absorb(seindom_sep_year_n) vce(cluster puma5)
outreg2 `depvar' `smvar' `control_output' ///
  using `vnum'_`vers'_`dep'_`suf'_`prox'_`lim'.xls, ///
  excel title("areg dependent:`dep' sufficient:`suf' proximity:`prox' limit:`lim'") ///
  ctitle("fe_empab_cluspuma_T3_3") addstat("Mean Dep Var",`meandep') onecol dec(4) append

* Table 3, Column 3: FE, Cluster by employer/year and PUMA
* ratio - employer/year FE, cluster employer/year and puma
local depvar="qtrL_hire_`dep'_`suf'"
local smvar="ratio_predfeas_all_`lim'"
local control_output="`contstand'"
local control_absorb=""
areg `depvar' `smvar' `control_output' `control_sec' `control_seas' `control_absorb' ///
  if qtr==8, absorb(seindom_sep_year_n) vce(cluster seindom_sep_year_puma5_n)
outreg2 `depvar' `smvar' `control_output' ///
  using `vnum'_`vers'_`dep'_`suf'_`prox'_`lim'.xls, ///
  excel title("areg dependent:`dep' sufficient:`suf' proximity:`prox' limit:`lim'") ///
  ctitle("fe_empab_clusemppuma_T3_3") addstat("Mean Dep Var",`meandep') onecol dec(4) append

* Use SE from above three models to compute two-way: SE=sqrt(empyr+geo-empyr_geo)

* Alternative to Table 3, Column 3: FE, Cluster by tract
* ratio - employer/year FE, cluster tract
local depvar="qtrL_hire_`dep'_`suf'"
local smvar="ratio_predfeas_all_`lim'"
local control_output="`contstand'"
local control_absorb=""
areg `depvar' `smvar' `control_output' `control_sec' `control_seas' `control_absorb' ///
  if qtr==8, absorb(seindom_sep_year_n) vce(cluster h_stfid)
outreg2 `depvar' `smvar' `control_output' ///
  using `vnum'_`vers'_`dep'_`suf'_`prox'_`lim'.xls, ///
  excel title("areg dependent:`dep' sufficient:`suf' proximity:`prox' limit:`lim'") ///
  ctitle("fe_empab_clustrt") addstat("Mean Dep Var",`meandep') onecol dec(4) append

* Alternative to Table 3, Column 3: FE, Cluster by employer/year and tract
* ratio - employer/year FE, cluster employer/year and tract
local depvar="qtrL_hire_`dep'_`suf'"
local smvar="ratio_predfeas_all_`lim'"
local control_output="`contstand'"
local control_absorb=""
areg `depvar' `smvar' `control_output' `control_sec' `control_seas' `control_absorb' ///
  if qtr==8, absorb(seindom_sep_year_n) vce(cluster seindom_sep_year_stfid_n)
outreg2 `depvar' `smvar' `control_output' ///
  using `vnum'_`vers'_`dep'_`suf'_`prox'_`lim'.xls, ///
  excel title("areg dependent:`dep' sufficient:`suf' proximity:`prox' limit:`lim'") ///
  ctitle("fe_empab_clusemptrt") addstat("Mean Dep Var",`meandep') onecol dec(4) append


************ Tables 4 and 5 **************

* list of groups
levelsof grp_c, local(grp_lev)

* produce for each group
foreach grp in `grp_lev' {

* mean dependent variable
sum qtr_hire_`dep'_`suf' if qtr==8 & grp_c==`grp'
local meandep=r(mean)

******* Table 4, Panel A: Race/ethnicity ****************
* all
local depvar="qtrL_hire_`dep'_`suf'"
local smvar="ratio_predfeas_all_`lim'"
local control_output="`contstand'"
local control_absorb="femy_fe*"
tobit `depvar' `smvar' `control_output' `control_sec' `control_seas' `control_absorb' ///
  if qtr==8 & grp_c==`grp', vce(cluster puma5) ll(-0.693) ul(2.251)
outreg2 `depvar' `smvar' `control_output' `control_sec' `control_seas' ///
  using `vnum'_`vers'_`dep'_`suf'_`prox'_`lim'.xls, ///
  excel title("tobit dependent:`dep' sufficient:`suf' proximity:`prox' limit:`lim'") ///
  ctitle("sub:grp`grp'") addstat("Mean Dep Var",`meandep') onecol dec(3) append

* Table F3: Magnitude of Accessibility Effects (only for new job earnings > 75pct old job)
* At Median: see Predictive margins, _at=4, Margin
* 25pct: see Predictive margins, _at=3, Margin
* 75pct: see Predictive margins, _at=5, Margin
* Interquartile Diff.: 75pct-25pct
estimates store jobsearch
marginal_effect_predval_grp val_`dep'`suf'_feas`lim' ratio_predfeas_all_`lim' `grp'

******* Table 5, Panel A: Race/ethnicity, same-type job accessibility ****************
* same
local depvar="qtrL_hire_`dep'_`suf'"
local smvar="ratio_predfeas_gp`grp'_`lim'"
local control_output="`contstand'"
local control_absorb="femy_fe*"
tobit `depvar' `smvar' `control_output' `control_sec' `control_seas' `control_absorb' ///
  if qtr==8 & grp_c==`grp', vce(cluster puma5) ll(-0.693) ul(2.251)
outreg2 `depvar' `smvar' `control_output' `control_sec' `control_seas' ///
  using `vnum'_`vers'_`dep'_`suf'_`prox'_`lim'.xls, ///
  excel title("tobit dependent:`dep' sufficient:`suf' proximity:`prox' limit:`lim'") ///
  ctitle("same:grp`grp'") addstat("Mean Dep Var",`meandep') onecol dec(3) append

}



* list of sectors
levelsof sep_sec_c, local(sep_sec_lev)

* produce for each sector
foreach sep_sec in `sep_sec_lev' {

* mean dependent variable
sum qtr_hire_`dep'_`suf' if qtr==8 & sep_sec_c==`sep_sec'
local meandep=r(mean)

******* Table 4, Panel D: Industry ****************
* all
local depvar="qtrL_hire_`dep'_`suf'"
local smvar="ratio_predfeas_all_`lim'"
local control_output="`contstand'"
local control_absorb="femy_fe*"
tobit `depvar' `smvar' `control_output' `control_sec' `control_seas' `control_absorb' ///
  if qtr==8 & sep_sec_c==`sep_sec', vce(cluster puma5) ll(-0.693) ul(2.251)
outreg2 `depvar' `smvar' `control_output' `control_sec' `control_seas' ///
  using `vnum'_`vers'_`dep'_`suf'_`prox'_`lim'.xls, ///
  excel title("tobit dependent:`dep' sufficient:`suf' proximity:`prox' limit:`lim'") ///
  ctitle("sub:sec`sep_sec'") addstat("Mean Dep Var",`meandep') onecol dec(3) append

******* Table 5, Panel B: Industry, same-type job accessibility ****************
* same
local depvar="qtrL_hire_`dep'_`suf'"
local smvar="ratio_predfeas_sc`sep_sec'_`lim'"
local control_output="`contstand'"
local control_absorb="femy_fe*"
tobit `depvar' `smvar' `control_output' `control_sec' `control_seas' `control_absorb' ///
  if qtr==8 & sep_sec_c==`sep_sec', vce(cluster puma5) ll(-0.693) ul(2.251)
outreg2 `depvar' `smvar' `control_output' `control_sec' `control_seas' ///
  using `vnum'_`vers'_`dep'_`suf'_`prox'_`lim'.xls, ///
  excel title("tobit dependent:`dep' sufficient:`suf' proximity:`prox' limit:`lim'") ///
  ctitle("same:sec`sep_sec'") addstat("Mean Dep Var",`meandep') onecol dec(3) append

}



* list of sexes
levelsof female, local(fem_lev)

* produce for each group
foreach fem in `fem_lev' {

* mean dependent variable
sum qtr_hire_`dep'_`suf' if qtr==8 & female==`fem'
local meandep=r(mean)

******* Table 4, Panel B: Sex ****************
* ratio
local depvar="qtrL_hire_`dep'_`suf'"
local smvar="ratio_predfeas_all_`lim'"
local control_output="`contstand'"
local control_absorb="femy_fe*"
tobit `depvar' `smvar' `control_output' `control_sec' `control_seas' `control_absorb' ///
  if qtr==8 & female==`fem', vce(cluster puma5) ll(-0.693) ul(2.251)
outreg2 `depvar' `smvar' `control_output' `control_sec' `control_seas' ///
  using `vnum'_`vers'_`dep'_`suf'_`prox'_`lim'.xls, ///
  excel title("tobit dependent:`dep' sufficient:`suf' proximity:`prox' limit:`lim'") ///
  ctitle("sub:fem`fem'") addstat("Mean Dep Var",`meandep') onecol dec(3) append

}



* list of ages
levelsof age_c3, local(age_lev)

* produce for each group
foreach age in `age_lev' {

* mean dependent variable
sum qtr_hire_`dep'_`suf' if qtr==8 & age_c3==`age'
local meandep=r(mean)

******* Table 4, Panel B: Age categories ****************
* ratio
local depvar="qtrL_hire_`dep'_`suf'"
local smvar="ratio_predfeas_all_`lim'"
local control_output="`contstand'"
local control_absorb="femy_fe*"
tobit `depvar' `smvar' `control_output' `control_sec' `control_seas' `control_absorb' ///
  if qtr==8 & age_c3==`age', vce(cluster puma5) ll(-0.693) ul(2.251)
outreg2 `depvar' `smvar' `control_output' `control_sec' `control_seas' ///
  using `vnum'_`vers'_`dep'_`suf'_`prox'_`lim'.xls, ///
  excel title("tobit dependent:`dep' sufficient:`suf' proximity:`prox' limit:`lim'") ///
  ctitle("sub:age`age'") addstat("Mean Dep Var",`meandep') onecol dec(3) append

}


* list of earner types
levelsof primeearn, local(primeearn_lev)

* produce for each group
foreach prime in `primeearn_lev' {

* mean dependent variable
sum qtr_hire_`dep'_`suf' if qtr==8 & primeearn==`prime'
local meandep=r(mean)

******* Table 4, Panel C: Household status ****************
* all
local depvar="qtrL_hire_`dep'_`suf'"
local smvar="ratio_predfeas_all_`lim'"
local control_output="`contstand'"
local control_absorb="femy_fe*"
tobit `depvar' `smvar' `control_output' `control_sec' `control_seas' `control_absorb' ///
  if qtr==8 & primeearn==`prime', vce(cluster puma5) ll(-0.693) ul(2.251)
outreg2 `depvar' `smvar' `control_output' `control_sec' `control_seas' ///
  using `vnum'_`vers'_`dep'_`suf'_`prox'_`lim'.xls, ///
  excel title("tobit dependent:`dep' sufficient:`suf' proximity:`prox' limit:`lim'") ///
  ctitle("sub:prime`prime'") addstat("Mean Dep Var",`meandep') onecol dec(3) append

}

******* Table 4, Panel C: Lower Earning ****************
* ratio, earn low
local depvar="qtrL_hire_`dep'_`suf'"
local smvar="ratio_predfeas_all_`lim'"
local control_output="`contstand'"
local control_absorb="femy_fe*"
tobit `depvar' `smvar' `control_output' `control_sec' `control_seas' `control_absorb' ///
  if qtr==8 & earn_c==1 | qtr==8 & earn_c==2 | qtr==8 & earn_c==3, vce(cluster puma5) ll(-0.693) ul(2.251)
outreg2 `depvar' `smvar' `control_output' `control_sec' `control_seas' ///
  using `vnum'_`vers'_`dep'_`suf'_`prox'_`lim'.xls, ///
  excel title("tobit dependent:`dep' sufficient:`suf' proximity:`prox' limit:`lim'") ///
  ctitle("sub:earn_l") addstat("Mean Dep Var",`meandep') onecol dec(3) append

******* Table 4, Panel C: Higher Earning ****************
* ratio, earn high
local depvar="qtrL_hire_`dep'_`suf'"
local smvar="ratio_predfeas_all_`lim'"
local control_output="`contstand'"
local control_absorb="femy_fe*"
tobit `depvar' `smvar' `control_output' `control_sec' `control_seas' `control_absorb' ///
  if qtr==8 & earn_c==4 | qtr==8 & earn_c==5, vce(cluster puma5) ll(-0.693) ul(2.251)
outreg2 `depvar' `smvar' `control_output' `control_sec' `control_seas' ///
  using `vnum'_`vers'_`dep'_`suf'_`prox'_`lim'.xls, ///
  excel title("tobit dependent:`dep' sufficient:`suf' proximity:`prox' limit:`lim'") ///
  ctitle("sub:earn_h") addstat("Mean Dep Var",`meandep') onecol dec(3) append
